/**
 * 在stestjs的版本这个你去除对express的依赖
 */
var http = require('http');
var httpServer = http.createServer();
var server = require('socket.io')(httpServer,{
    pingTimeout: 1000 * 10, //default 1000 * 60,超时时间
    pingInterval: 1000 * 2, //default 1000 * 2.5 ping的频率
    transports: ['websocket', 'polling'],
    allowUpgrades: true, //default true, 传输方式是否允许升级
    httpCompression: true, //default true,使用加密
    serveClient: false //是否提供客户端js（socket.io-client）
});
var port = process.env.PORT || 3000;
var clientList = new Map();
server.on('connection', function(socket) {
    console.log('socketid:',socket);
    //接受消息
    // clientList.set(socket.id,socket);

    socket.on('server.online', (nickName) => {
        socket.nickName = nickName;
        server.emit('client.online', nickName+"，欢迎你");
    });

    socket.on('server.message',(message)=>{
         console.log("客户端发送的消息：",message,socket.id);
         server.emit('client.message', '服务器');
    });

    //断开连接回调--客户端断开连接
    socket.on('disconnect', function () { 
        console.log("断开链接了");
    });
});



httpServer.listen(port, function () {
    console.log('inewhome tool sk port %d', port);
});